#include "comm.hpp"

extern Log log;

int main()
{
    //创建共享内存
    int shmid = Share_Memory::creat();
    sleep(2);
    //挂接共享内存
    char* shmaddr = Share_Memory::load(shmid);

    //使用命名管道
    FIFO fifo;
    int fd = FIFO::open_read(FIFO_FILE);

    //进程通信代码
    while (true)
    {
        char sign = 0;
        int n = read(fd, &sign, sizeof(sign));
        if (n == sizeof(sign))
            std::cout << "client sent: " << shmaddr << std::endl;
        else if (n == 0)
        {
            std::cout << "client quit" << std::endl;
            sleep(2);
            break;
        }
        sleep(1);
    }
    close(fd);

    //去关联共享内存
    Share_Memory::unload(shmaddr);
    sleep(2);
    //删除共享内存
    Share_Memory::free(shmid);

    return 0;
}
